package com.noble.glamour.ui.pay;

import android.support.v4.app.FragmentActivity;
import android.view.View;

import com.noble.library.log.PToast;
import com.noble.glamour.R;
import com.noble.pay.bean.PayWX;
import com.noble.pay.bean.PayGood;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.glamour.module.logic.config.UrlParam;
import com.noble.glamour.module.logic.request.HttpResponse;
import com.noble.glamour.module.logic.request.RequestComplete;
import com.noble.glamour.ui.pay.utils.PayAlipayUtils;

/**
 * 支付宝支付条目
 */
public class PayAlipayPannel extends BasePayPannel {


    public PayAlipayPannel(FragmentActivity activity, PayGood payGood) {
        super(activity, payGood);
        setImageIcon(R.drawable.y2_paytype_alipay);
        setTextTitle("支付宝");
        setTextRemark("推荐支付宝用户使用");
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        ModuleMgr.getCommonMgr().reqCUPOrAlipayMethod(UrlParam.reqAlipay, getOutTradeNo(), getPayGood().getPay_name(),
                getPayGood().getPay_id(), getPayGood().getPay_money(), new RequestComplete() {
                    @Override
                    public void onRequestComplete(HttpResponse response) {
                        PayWX payWX = new PayWX(response.getResponseString(), true);
                        if (!payWX.isOK()) {
                            PayConst.out_trade_no = "";
                            PayConst.payGood = null;
                            PToast.showShort("请求失败，请稍后再试");
                            return;
                        }
                        PayConst.out_trade_no = payWX.getOut_trade_no();
                        PayConst.payGood = getPayGood();

                        new PayAlipayUtils(getActivity()).pay(payWX.getCupPayType(), payWX.getParam());
                    }
                });
    }
}
